package com.tedu.review.test;

import java.util.Objects;

/**
 * equals 方法
 * 测试类：China类---属性：city county
 */
public class Object判断 {
    public static void main(String[] args) {
        //创建两个China类
        China c1=new China();
       c1.city="唐山";
       c1.county="曹妃甸";
        China c2=new China();
        c2.city="唐山";
        c2.county="曹妃甸";
        System.out.println(c2);
        //equals()默认 Object类提供  比  地址值----逻辑修改：市跟县是否相等
        System.out.println(c1.equals(c2));
    }
}
class China {
    public String city; //市
    public String county; //县

    //重写 equals方法：判断China中市和县是否相等
    public boolean equals(Object o) {
        //①将Object超类 强转为China；向下造型
        China china = (China) o;
        //②China对象拿到调属性：city county
        boolean c = this.city.equals(china.city);
        //当前China对象的city属性与拿到China参数中city对比
        boolean y = this.county.equals(china.county);
        //两两对比之后，全部都是正确  弹出true  否则 folse
    return c&&y;
    }
}


